package com.fesine.quartz.chapter4;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @description: 将jobDetail和trigger添加到scheduler中
 * @author: Fesine
 * @createTime:2016/11/19 16:26
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/11/19 16:26
 */
public class Listing_4_4 {
    static Log logger = LogFactory.getLog(Listing_4_4.class);

    public static void main(String[] args) {
        Listing_4_4 example = new Listing_4_4();
        example.runScheduler();
    }

    public void runScheduler() {
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            logger.info("Scheduler starting up...");
            scheduler.start();
            JobDetail jobDetail = new JobDetail("PrintJob", Scheduler.DEFAULT_GROUP, PrintJob
                    .class);
            Trigger trigger = TriggerUtils.makeImmediateTrigger(SimpleTrigger.REPEAT_INDEFINITELY,
                    10000);
            trigger.setName("PrintJobTrigger");
            scheduler.scheduleJob(jobDetail, trigger);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
